//
//  main.m
//  OC_7数据练习
//
//  Created by JR_Rafael on 15/12/10.
//  Copyright © 2015年 lanou3g. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    
    // 找到文件的路径
    NSString *path = @"/Users/rafael/Desktop/1136/OC相关/OC_7数据练习/movielist.txt";
    
    // 数据类型
    NSData *data = [NSData dataWithContentsOfFile:path];
    
    // 转化为我们的数据格式
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
    
    // 取出一个电影名字
//    NSLog(@"%@", dic);
//    NSArray *mvArr = [dic objectForKey:@"result"];
//    NSDictionary *mvDic = [mvArr objectAtIndex:0];
//    NSString *str = [mvDic objectForKey:@"movieName"];
//    
//    NSString *str1 = dic[@"result"][0][@"movieName"];
//    
//    NSLog(@"%@", str1);
    
    
//    
//    NSArray *mvArr = [dic objectForKey:@"result"];
//    
//    for (NSDictionary *dic in mvArr) {
//        
//        NSString *mvName = [dic objectForKey:@"movieName"];
//        NSLog(@"%@", mvName);
//        
//    }
//    
//    for (NSDictionary *dic in mvArr) {
//        NSString *name = dic[@"movieName"];
//        NSString *mvId = dic[@"movieId"];
//        NSString *result = [name stringByAppendingString:mvId];
//        NSLog(@"%@", result);
//    }

    
    
    // 找到文件路径
    NSString *path1 = @"/Users/rafael/Desktop/1136/OC相关/OC_7数据练习/activitylist.txt";
    // 转化为数据
    NSData *data1 = [NSData dataWithContentsOfFile:path1];
    // 解析数据
    NSDictionary *dic1 = [NSJSONSerialization JSONObjectWithData:data1 options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@", dic1);
    
//    NSString *str = dic1[@"events"][0][@"content"];
//    NSLog(@"%@", str);
    
//    NSArray *arr1 = [dic1 objectForKey:@"events"];
//    for (NSDictionary *dic in arr1) {
//        
//        NSString *content = [dic objectForKey:@"content"];
//        NSLog(@"%@", content);
//        
//    }
    
//    "begin_time" = "2014-07-22 09:00:00";
//    "end_time" = "2014-10-16 17:00:00";
    
    // 07-22 09:00 -- 10-16 17:00
    
    NSArray *event = [dic1 objectForKey:@"events"];
    NSDictionary *eventDic = [event objectAtIndex:0];
    
    NSString *beginTime = [eventDic objectForKey:@"begin_time"];
    NSString *endTime = [eventDic objectForKey:@"end_time"];
    NSLog(@"%@", beginTime);
    NSLog(@"%@", endTime);
    
    NSString *newBegin = [beginTime substringWithRange:NSMakeRange(5, 11)];
    NSString *newEnd = [endTime substringWithRange:NSMakeRange(5, 11)];
    NSString *newTime = [NSString stringWithFormat:@"%@ -- %@", newBegin, newEnd];
    NSLog(@"%@", newTime);
    
    
    
    for (NSDictionary *dic in event) {
        
        NSString *begin = [dic objectForKey:@"begin_time"];
        NSString *end = [dic objectForKey:@"end_time"];
        
        NSString *new1 = [begin substringWithRange:NSMakeRange(5, 11)];
        NSString *new2 = [end substringWithRange:NSMakeRange(5, 11)];
        NSString *newnew = [NSString stringWithFormat:@"%@ -- %@", new1, new2];
        NSLog(@"%@", newnew);
        
    }
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}
